package com.tw.people.util;

import au.com.bytecode.opencsv.CSVReader;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * Created by IntelliJ IDEA.
 * User: twer
 * Date: 12/18/11
 * Time: 2:50 PM
 * To change this template use File | Settings | File Templates.
 */
public class CsvLoader {
    public TimeSheetRecordSet load(String cvsFileName) throws IOException {
        InputStream resourceAsStream = ClassLoader.getSystemResourceAsStream(cvsFileName);
        CSVReader reader = new CSVReader(new InputStreamReader(resourceAsStream));
        
        TimeSheetRecordSet csv = new TimeSheetRecordSet();
        String[] line = null;
        while ( (line = reader.readNext()) != null) {
            csv.add(line[0], line[1], line[2]);
        }

        return csv;
    }
}
